package orders

import (
	"gin_demo/utility"

	"github.com/gin-gonic/gin"
)

var ORder = Order{}

type Order struct{}

//@Summary  后台订单数据添加接口
//@Success 200 {string} string json{"code","message"}
//@Param Authorization	header string true "Bearer 31a165baebe6dec616b1f8f3207b4273"
//@Param data body AddOrderReq{} true "添加请求参数"
//@Router /backend/order/add [post]
//@version 1.0
func (order *Order) Create(ctx *gin.Context) {
	req := AddOrderReq{}
	err := ctx.ShouldBindJSON(&req)
	if err != nil {
		utility.Fail(ctx, err.Error())
	} else {
		AddOrder(ctx, req)
	}
}

//@Summary  后台订单数据列表接口
//@Success 200 {string} string json{"code","message"}
// @Param Authorization	header string true "Bearer 31a165baebe6dec616b1f8f3207b4273"
//@Param Limit query int true "一次性最大页数"
//@Param Page query int true "当前页数"
//@Router  /backend/order/list  [get]
//@version 1.0
func (order *Order) List(ctx *gin.Context) {
	req := OrderRes{}
	err := ctx.ShouldBind(&req)
	if err != nil {
		utility.Fail(ctx, err.Error())
	} else {
		List(ctx, req)
	}
}

//@Summary  后台订单数据删除接口
//@Success 200 {string} string json{"code","message"}
// @Param Authorization	header string true "Bearer 31a165baebe6dec616b1f8f3207b4273"
//@Param data body admin.SoftDeleteReq{} true "删除请求参数"
//@Router  /backend/order/del  [delete]
//@version 1.0
func (order *Order) Delete(ctx *gin.Context) {
	req := SoftDeleteReq{}
	err := ctx.ShouldBind(&req)
	if err != nil {
		utility.Fail(ctx, err.Error())
	} else {
		Delete(ctx, req)
	}
}

//@Summary  后台订单修改接口
//@Success 200 {string} string json{"code","message"}
//@Param Authorization	header string true "Bearer 31a165baebe6dec616b1f8f3207b4273"
//@Param data body UpdateOrderReq{} true "更新请求参数"
//@Router /backend/order/update [put]
//@version 1.0
func (order *Order) Update(ctx *gin.Context) {
	req := UpdateOrderReq{}
	err := ctx.ShouldBind(&req)
	if err != nil {
		utility.Fail(ctx, err.Error())
	} else {
		Update(ctx, req)
	}
}

//@Summary  后台订单搜索接口
//@Success 200 {string} string json{"code","message"}
//@Param Authorization	header string true "Bearer 31a165baebe6dec616b1f8f3207b4273"
//@Param Limit query int true "一次性最大页数"
//@Param Page query int true "当前页数"
//@Param Type query string true "搜索类型"
//@Param Number query string false "订单编号"
//@Param OrderClass query string false "订单类型"
//@Param Status query int false "订单状态"
//@Param PayType query int false "支付方式"
//@Router /backend/order/search [get]
//@version 1.0
func (order *Order) Search(ctx *gin.Context) {
	req := SearchOrder{}
	err := ctx.ShouldBind(&req)
	if err != nil {
		utility.Fail(ctx, err.Error())
	} else {
		Search(ctx, req)
	}
}
